package com.sample.action;
/**
 * 参合信息action
 */
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.sample.action.form.PersinfoForm;
import com.sample.javabean.Persinfo;
import com.sample.javabean.ZcPolicy;
import com.sample.util.Pager;


public class PersinfoAction extends BaseAction{
	private final static Log log=LogFactory.getLog(PersinfoAction.class);
	private Pager<Persinfo> pageList;
	private String cardNo ;
	private String persName;
	private String sex;
	private String age;
	private String address;
	private String tel;
	private String invNumber;
	private String persNumber;
	private String joinYear;
	private Persinfo persinfo=new Persinfo();
	private PersinfoForm persinfoForm=new PersinfoForm();
	private List<ZcPolicy> zcPolicyList;

	public List<ZcPolicy> getZcPolicyList() {
		return zcPolicyList;
	}

	public void setZcPolicyList(List<ZcPolicy> zcPolicyList) {
		this.zcPolicyList = zcPolicyList;
	}

	
	/**
	 * 参合信息录入界面
	 * @return
	 * @throws Exception
	 */
	public String inputPersinfo()throws Exception{
		
		return "inputPersinfo";
	}
	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	public String save()throws Exception{
		try{
			log.info("保存参合信息");
			//Form属性接值，由struts2框架自动完成属性值注入
			if(persinfoForm!=null){
				Persinfo persinfo =new Persinfo();
			   //将persinfoForm中的属性值一一赋予的对应的属性。
				persinfo.setCardNo(persinfoForm.getCardNo());
				persinfo.setPersName(persinfoForm.getPersName());
				persinfo.setSex(persinfoForm.getSex());
				persinfo.setAge(persinfoForm.getAge());
				persinfo.setAddress(persinfoForm.getAddress());
				persinfo.setTel(persinfoForm.getTel());
				persinfo.setJoinYear(persinfoForm.getJoinYear());
				persinfo.setInvNumber(persinfoForm.getInvNumber());
				persinfo.setPersNumber(persinfoForm.getPersNumber());
			   
			   //调用add方法
			   persinfo.add(persinfoForm);
			}
			return SUCCESS;
		}catch (Exception e) {
			e.printStackTrace();
			
		}
		return "inputPersinfo";
	}
	/**
	 *显示信息
	 * @return
	 * @throws Exception
	 */
	public String list()throws Exception{
		Persinfo persinfoModel =new Persinfo();
		pageList =persinfoModel.list(page, size, persinfoForm);
		return "listPersinfo";
	}
	/**
	 * 删除
	 * @return
	 * @throws Exception
	 */
	public String del()throws Exception{
		try{
			if(persinfoForm!=null){
				log.info("add User:"+persinfoForm.getPersNumber());
				persinfo.setPersNumber(persNumber);
				persinfo.delPersinfo();	
			}
			return SUCCESS;
		}catch (Exception e) {
			e.printStackTrace();
			throw e;
		}	
	}
	/**
	 * 编辑
	 * @return
	 * @throws Exception
	 */
	public String editPersinfo()throws Exception{
		try{
			persinfo.setPersNumber(persNumber);
			persinfo.load();
			return "editPersinfo";
		}catch (Exception e) {
			e.printStackTrace();
			throw e;
		}	
	}
	/**
	 * 编辑参合信息
	 * @return
	 * @throws Exception
	 */
	public String edit()throws Exception{
		try{
			if(persinfoForm!=null){
				persinfo.setCardNo(persinfoForm.getCardNo());
				persinfo.setPersName(persinfoForm.getPersName());
				persinfo.setSex(persinfoForm.getSex());
				persinfo.setAge(persinfoForm.getAge());
				persinfo.setAddress(persinfoForm.getAddress());
				persinfo.setTel(persinfoForm.getTel());
				persinfo.setJoinYear(persinfoForm.getJoinYear());
				persinfo.setInvNumber(persinfoForm.getInvNumber());
				persinfo.setPersNumber(persinfoForm.getPersNumber());
				persinfo.editPersinfo();	
			}
			return SUCCESS;
		}catch (Exception e) {
			e.printStackTrace();
			throw e;
		}	
	}	
		/**
		 *校验能否报销
		 */

	public String checkmx() throws Exception {
		try {
			String aa = "0";
			if (persinfoForm != null) {
				persinfo.setCardNo(persinfoForm.getCardNo());
				System.out.println("cardNo=" + cardNo);
				aa = persinfo.checkmxs(cardNo);
				System.out.println("aa=" + aa);
				System.out.println("the cardNo=" + cardNo);
			}
			ZcPolicy zcPolicy=new ZcPolicy();
			zcPolicyList =zcPolicy.findAll();
			if (aa == "1") {
				return "yes";
			}
			else if(aa=="3"){
				return "no";
			}
			else if(aa=="0"){
				return "no1";
			}			
			else{
				return "no2";
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception("信息有误:" + e.getMessage());
		}

	}

	public Pager<Persinfo> getPageList() {
		return pageList;
	}
	public void setPageList(Pager<Persinfo> pageList) {
		this.pageList = pageList;
	}
	public String getCardNo() {
		return cardNo;
	}
	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}
	public String getPersName() {
		return persName;
	}
	public void setPersName(String persName) {
		this.persName = persName;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public String getAge() {
		return age;
	}
	public void setAge(String age) {
		this.age = age;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	public String getInvNumber() {
		return invNumber;
	}
	public void setInvNumber(String invNumber) {
		this.invNumber = invNumber;
	}
	public String getPersNumber() {
		return persNumber;
	}
	public void setPersNumber(String persNumber) {
		this.persNumber = persNumber;
	}
	public Persinfo getPersinfo() {
		return persinfo;
	}
	public void setPersinfo(Persinfo persinfo) {
		this.persinfo = persinfo;
	}
	public PersinfoForm getPersinfoForm() {
		return persinfoForm;
	}
	public void setPersinfoForm(PersinfoForm persinfoForm) {
		this.persinfoForm = persinfoForm;
	}
	public String getJoinYear() {
		return joinYear;
	}
	public void setJoinYear(String joinYear) {
		this.joinYear = joinYear;
	}
	

}
